﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcMusicStore.Models;

namespace MvcMusicStore.Repositories
{
    public class CartItemRepository
    {
        public MusicStoreEntities Context { get; private set; }
        public CartItemRepository(MusicStoreEntities ct)
        {
            Context = ct;
        }

        public List<CartItem> GetAll()
        {
            throw new NotImplementedException();
        }

        public List<CartItem> GetByCartId(int id)
        {
            return Context.CartItems.Where(s => s.CartId == id).ToList();
        }

        public CartItem GetById(int id)
        {
            throw new NotImplementedException();
        }

        public void Add(CartItem item)
        {
            Context.CartItems.Add(item);
        }

        public void EmptyCartItemsByCartId(int id)
        {
            Context.CartItems.Where(s => s.CartId == id).ToList().ForEach(s => Context.CartItems.Remove(s));
        }

        public void Edit(CartItem item)
        {
            throw new NotImplementedException();
        }

        public void Delete(int id)
        {
            var itemToDelete = Context.CartItems.Find(id);
            Context.CartItems.Remove(itemToDelete);
        }

        public List<CartItem> GetPager(int pageIndex, int pageSize)
        {
            throw new NotImplementedException();
        }
    }
}